<!-- 下单 -->
<template>
	<view class="page" :style="{'--color':color}">
		<!-- 	<status-bar title='提交订单'></status-bar> -->
		<backTop v-if='toTop'></backTop>
		<!-- 收货方式 -->
		<view class="infobar">
			<view class="infobar_t">收货方式</view>
			<view class="infobar_c d-flex" v-if='pageData && pageData.deliverys'>
				<view class="d-flex a-center m-left20" @click="selectWays(2)" v-if='pageData.deliverys.indexOf("2")>-1'>
					<view class="fake-radio" :class="delivery==2?'thmeBorder thmeBg':''" :style="{'--color': color}">
						<text class="icon-xuanzhong iconfont"></text>
					</view>门店自提
				</view>
				<view class="d-flex a-center m-left20" @click="selectWays(1)" v-if='pageData.deliverys.indexOf("1")>-1'>
					<view class="fake-radio" :class="delivery==1?'thmeBorder thmeBg':''" :style="{'--color': color}">
						<text class="icon-xuanzhong iconfont"></text>
					</view>快递上门
				</view>
				<view class="d-flex a-center m-left20" @click="selectWays(5)" v-if='pageData.deliverys.indexOf("5")>-1'>
					<view class="fake-radio" :class="delivery==5?'thmeBorder thmeBg':''" :style="{'--color': color}">
						<text class="icon-xuanzhong iconfont"></text>
					</view>暂存仓库
				</view>
			</view>
		</view>

		<!-- 收货地址 -->
		<view class="receipt_addr">
			<!-- 快递 -->
			<view v-show="delivery==1" @click="toUrl(`/orderPage/Addresslist/Addresslist`)">
				<!-- 未选择 -->
				<view class="unreceipt_addr choose_wxaddr" v-if='!addDetail.Aaddress'>
					<text class="unreceipt_addr_text">添加收货地址</text>
				</view>

				<!-- 已选择 -->
				<view class="logistics_addr" v-else>
					<view class="address_icon to45deg" :style="{'--color': color,'--color_aid': color_aid}">
						<text class="icon-dingwei iconfont color_66"></text>
					</view>
					<view class="r_addr_info flex">
						<view class="r_addr_info_c">
							{{addDetail.Aregion?addDetail.Aregion:''}}
						</view>
						<view class="r_addr_info_t">
							{{addDetail.Aaddress?addDetail.Aaddress:' '}}
						</view>
						<view class="r_addr_info_c">
							{{addDetail.Aname?addDetail.Aname:' '}}&nbsp;&nbsp;{{addDetail.Amobile?addDetail.Amobile:' '}}
						</view>
					</view>
					<text class="iconfont icon-xiangyouxiayiye"></text>
				</view>

				<view v-if="buy_config.state == 1" class="flex-box idCardBox align-center"
					@click.stop="id_number_update(1)">
					<view>身份证号码：</view>
					<view class="flex pla" v-if='!ID_number'>请输入身份证号码</view>
					<view class="flex input" v-else>{{ID_number}}</view>
				</view>


				<!-- 键盘 -->
				<view @click.stop="showKeyBoard=false" v-if="showKeyBoard" class="keyboard-box">
					<view class="keyboard">
						<view class="keyboard-close">
							<text class="icon-xiangxia iconfont"></text>
						</view>
						<view class="key-box flex-box">
							<view class="key flex-box flex-center align-center" @click.stop="checkNum(i)"
								v-for="i in numList" :key='i'>
								<view class="key-txt">{{i}}</view>
							</view>
							<view class="key flex-box flex-center align-center" @click.stop="delNum()">
								<view class="key-txt">
									<text class="iconfont icon-shanchu1"></text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 自提 -->
			<view class="store_addr" v-show="delivery==2">
				<view class="r_addr_info  p-re" v-if='pageData.data'>
					<view class="r_addr_info_t flex-box align-center">
						<text>{{pageData.data[0].shopName?pageData.data[0].shopName:shopName}}</text>
						<!-- <text>{{pageData.data[0].shopTel?pageData.data[0].shopTel:shopTel}}</text> -->
					</view>
					<view class="r_addr_info_c">
						{{pageData.data[0].shopAddress?pageData.data[0].shopAddress:shopAddress}}
					</view>
					<!-- <view class="iconfont icon-xiangyouxiayiye size26 color_33 selectStore"></view> -->
				</view>
				<view class="store_addr_form">
					<view class="input_box">
						<view class="isKey">姓名：</view>
						<input type="text" name="" v-model="buy_name" placeholder="请输入购买人姓名" />
					</view>
					<view class="input_box">
						<view class="isKey">电话：</view>
						<input type="number" name="" v-model="buy_phone" placeholder="请输入购买人电话" />
					</view>
				</view>
			</view>
		</view>

		<!-- 开团 -->
		<view class="gbuy_user mb_03" v-if='open_group == 1'>
			<view class="f_032">立即支付，即可开团</view>
			<view class="gbuy_user_list">
				<view class="gbuy_user_item">
					<image @error="pageData.headImg=''"
						:src="pageData.headImg?$imgUrls(pageData.headImg):staticUrl+'/images/jh_up/head.jpg'"
						class="gbuy_user_avatar" mode="aspectFill"></image>
					<text class="tag color5">待支付</text>
				</view>
				<view class="gbuy_user_item">
					<text class="icon-gengduo1 iconfont"></text>
				</view>
			</view>
		</view>


		<!-- 参团用户 -->
		<view class="gbuy_user mb_03" v-if='group_id && pageData.groupUsers'>
			<view class="f_032" v-if='pageData.missPeople>0'>还差 <text class="thmeColor" :style="{'--color': color}"
					style="font-size: 32rpx;font-weight: bold;">{{pageData.missPeople}}</text> 人即可成团</view>
			<view class="f_032" v-else>已满员</view>
			<view class="gbuy_user_list">
				<view class="gbuy_user_item" v-for='(head,hh) in pageData.groupUsers' :key='hh'>
					<image :src="$imgUrls(head.v_headimg)" class="gbuy_user_avatar" mode="aspectFill"></image>
					<text class="tag color5" v-if='head.v_id == pageData.main_v_id'>团长</text>
				</view>
				<view class="gbuy_user_item">
					<text class="iconfont icon-gengduo1"></text>
				</view>
			</view>
		</view>

		<!-- 下单产品 -->
		<template v-if='pageData.data'>
			<view class="order_goods" v-for="(item,index) in pageData.data" :key='index'>
				<view class="shop flex-box align-center">
					<image v-if='item.shopLogo' @error="item.shopLogo = ''" :src="$imgUrls(item.shopLogo)"
						mode="aspectFill" class="shop-logo"></image>
					<text v-else class="iconfont icon-dianpu"></text>
					<text class="name">{{item.shopName?item.shopName:shopName}}</text>
				</view>

				<view class="agoods" v-for="(item1,index1) in item.list" :key='index1'>
					<view class="agoods_thumb">
						<image :src="$imgUrls(item1.img)" class="agoods_thumb_img" mode="aspectFill"></image>
					</view>
					<view class="agoods_info flex-box">
						<view class="agoods_t lines2">{{item1.name}}</view>
						<view class="specs-show" v-if="item1.operation_text">
							<text>规格：{{item1.operation_text}}</text>
						</view>
						<view class="agoods_info_info">
							<view class="price4">
								<text class="price4_num myPrice">{{item1.price}}</text>
							</view>
							<view class="ff_a c_999999">x{{item1.num}}</view>
						</view>
					</view>
				</view>
				<view class="info_input" style="margin-top: 20upx;">
					<view class="info_input_t">订单备注</view>
					<textarea class="flex-1" v-model="remark" placeholder="选填，给商家留言" auto-height
						:maxlength="-1"></textarea>
				</view>
			</view>
		</template>


		<!-- 金额信息 -->
		<view class="info_list mb_03 p-top30 p-bot30">
			<view class="row j-sb">
				<view class="info_l_item_t size28">{{nameDefinition.goodsName}}金额</view>
				<view class="info_l_item_c">
					<view class="ff_a c_ff4400  myPrice">{{parseFloat(pageData.totalMoney).toFixed(2)}}</view>
				</view>
			</view>

			<view class="row j-sb m-top20">
				<view class="info_l_item_t size28">运费</view>
				<view class="info_l_item_c">
					<view class="ff_a c_ff4400 myPrice">
						{{pageData.express?parseFloat(pageData.express).toFixed(2):'0.00'}}
					</view>
				</view>
			</view>
			<!--  店铺活动 -->
			<view class="row m-top20" v-if="integralData.actMoney> 0">
				<view class="row j-sb a-center">
					<view class="info_l_item_t size28">{{integralData.usedActTitle}}</view>
					<view class=" d-flex">
						<view class="c_ff4400">-</view>
						<view class="ff_a c_ff4400 myPrice">{{integralData.actMoney}}</view>
					</view>
				</view>
				<view class="row h6 color_99 ">{{integralData.actDiscount.act_title}}</view>
			</view>
			<!-- 会员折扣 -->
			<view class="row m-top20" v-if="integralData && integralData.vipAct.vipMoney > 0">
				<view class="row j-sb">
					<view class="size28">{{integralData.vipAct.vipActTitle}}</view>
					<view class="d-flex c_ff4400">
						<text>-</text>
						<view class="myPrice h6" v-if="integralData">{{integralData.vipAct.vipMoney}}</view>
					</view>
				</view>
				<view class="row h6 color_99">{{integralData.vipAct.vipActName}}</view>
			</view>
		</view>


		<!-- 优惠信息(砍价商品暂不可叠加使用) -->
		<view class="info_list mb_03" v-if="!record_id">
			<view class="info_list_item" v-if="couponsData">
				<view class="info_l_item_t">使用优惠券</view>
				<view class="info_l_item_c">
					<view class="ff_a c_ff4400">
						<label class="option_label" @click="preferential(1)">
							<view class="fake-radio" :class="couponID?'thmeBorder thmeBg':''"
								:style="{'--color': color}">
								<text class="iconfont icon-xuanzhong"></text>
							</view>使用优惠券
						</label>
					</view>
				</view>
			</view>
			<view style="padding-bottom: 20rpx;" v-if="couponID">
				<view class="couponTip flex-box align-center">
					<view class="flex">
						使用
						"<text class="integralText" v-for="(con,i) in integralData.usedCoupon"
							:key='i'>{{con.title}}</text>"
					</view>
					<text class="integralText">-￥{{integralData.disMoney}}</text>
				</view>
			</view>
			<view class="info_list_item"
				v-if="parseFloat(integralData.exchangeFen) > 0 || parseFloat(integralData.genToMoney) > 0">
				<view class="info_l_item_t" style="width: 170%;">
					使用<text class="integralText">{{integralData.exchangeFen}}</text>积分可优惠<text
						class="integralText">{{parseFloat(integralData.genToMoney).toFixed(2)}}</text>元
				</view>
				<view class="info_l_item_c">
					<view class="ff_a c_ff4400">
						<label class="option_label" @click="preferential(0)">
							<view class="fake-radio" :class="useIntegral==1?'thmeBorder thmeBg':''"
								:style="{'--color': color}">
								<text class="iconfont icon-xuanzhong"></text>
							</view>
							使用积分
						</label>
					</view>
				</view>
			</view>
		</view>

		<!-- 平台通告信息 -->
		<view class="info_list mb_03 p-top30 p-bot30" v-if="pageData.tipsText">
			<u-parse :content="pageData.tipsText" :domain="$imgUrl"></u-parse>
		</view>

		<!-- 底部信息 -->
		<view class="footer_info">
			<view class="ftr_info_price">
				实付：
				<view class="price5">
					<text
						class="price5_num myPrice">{{paymentMoney==0?'0.00':parseFloat(paymentMoney).toFixed(2)}}</text>
				</view>
			</view>
			<view class="ftr_info_oper2">
				<view id="pay_btn" @click="play_btns" class="ftr_info_oper_item2 r thmeBg" :style="{'--color': color}">
					立即支付</view>
			</view>
		</view>



		<!-- 选择优惠券 -->
		<couponCheck :list='couponsData' v-if='selectCouponIsShow' @change='_couponClick'
			@close='selectCouponIsShow=false' :couponID='couponID'></couponCheck>

		<showModel type='99' v-if='showModal' title="是否确定支付" msg='支付成功后可在我的订单中查看' btn1='取消' btn2='去支付'
			@certain='paySure' @cancelFunc='showModal=false'></showModel>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import couponCheck from "../components/couponCheck.vue"
	let that;
	export default {
		components: {
			couponCheck
		},
		data() {
			return {

				color: getApp().globalData.color,
				color_aid: getApp().globalData.color_aid,

				toTop: false,
				buy_phone: "",
				buy_name: "",
				pageData: '',
				imgUrl: this.imgUrl,
				remark: '',
				addList: [], // 收货地址列表

				addDetail: {}, // 当前地址
				delivery: 0,

				shopName: uni.getStorageSync('startUp').title,
				shopAddress: uni.getStorageSync('startUp').service_address,
				shopTel: uni.getStorageSync('startUp').service_tel,
				sumbmitName: '', // 提交订单的name
				sumbmitPhone: '', // 提交订单的phone
				showModal: false, // 是否显示模态框
				staticUrl: this.staticUrl,
				flagPay: true, // 避免多次提交订单


				Aregion: "", // 收货地址区域 用于计算运费

				record_id: '',
				goods_id: '',
				goods_num: '',
				group_id: '',
				specs: '', // 规格
				car_id: '',
				open_group: 0, // 是否为开团 1为开团

				paymentMoney: 0, //实付款

				couponsData: '',
				selectCouponIsShow: false,
				integralData: '',
				useIntegral: 0, // 是否使用积分 0不使用 1使用
				couponID: '', // 优惠券ID








				ID_number: '', //身份证号码
				ID_number2: '',
				numList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 'X', 0],
				buy_config: '', // 商品购买信息如是否需要身份证
				showKeyBoard: false,
				keyBoardNum: 1, // 输入的是第几个身份证

			}
		},

		onLoad(options) {
			let that = this;
			uni.removeStorageSync('newStroe');

			// 砍价
			if (options.record_id) that.record_id = options.record_id

			// 单独购买
			if (options.goods_id) {

				that.goods_id = options.goods_id;
				that.goods_num = options.goods_num;
			}

			// 购物车购买
			if (options.car_id) {
				that.car_id = options.car_id;
			}

			// 参团购买
			if (options.group_id) {
				that.group_id = options.group_id;
			}

			// 开团购买
			if (options.open_group) {
				that.open_group = options.open_group;
			}

			// 规格信息
			if (options.specs_bind_id) {
				that.specs = {
					specs_bind_id: options.specs_bind_id,
					specs_bind_text: options.specs_bind_text,
				}
			}

		},
		onShow() {
			that = this;
			that.showModal = false;
			if (uni.getStorageSync('path') == '11') { // 订单页返回
				this.backHome()
			}
			if (uni.getStorageSync('path') == '1') { // 收银台返回 
				that.showModal = true;
				that.modelType = 8;
			}

			let newStore = uni.getStorageSync('newStroe');
			if (newStore && this.delivery == 2) {
				this.pageData.data[0].shopName = newStore.name;
				this.pageData.data[0].shopAddress = newStore.address;
				this.pageData.data[0].shop_id = newStore.shop_id;
			}

			that.getOldAddress()
		},
		methods: {
			addAddress(editId) {
				let that = this;
				let param = '';
				if (editId)
					param += '&editId=' + editId
				if (that.goods_id)
					param += '&goods_id=' + that.goods_id
				if (that.goods_num)
					param += '&goods_num=' + that.goods_num
				if (that.car_id)
					param += '&car_id=' + that.car_id
				if (that.group_id)
					param += '&group_id=' + that.group_id
				if (that.open_group)
					param += '&open_group=' + that.open_group
				if (that.specs)
					param = param + '&specs_bind_id=' + that.specs.specs_bind_id + '&specs_bind_text=' + that.specs
					.specs_bind_text
				console.log(param)
				uni.navigateTo({
					url: '/orderPage/order/addAddress?page_type=2' + param
				})
			},
			getOldAddress() {
				let that = this;
				that.$http.get({
					url: '/SRA_simMallApi/getOldAddress',
					data: {

						type: 3
					}
				}).then(res => {
					if (res.code == 100 && res.data) {
						that.addDetail = res.data
						that.Aregion = res.data.Aregion + res.data.Aaddress
						that.buy_name = res.data.uName
						that.buy_phone = res.data.uTel
					}
					that.getPageData()
				})
			},



			selectWays: function(num) {
				let that = this;
				that.delivery = num;
				that.getPageData()
			},
			play_btns: function() {
				let that = this;
				var name, tel;
				if (that.delivery == 2) { // 自提
					if (!that.buy_name.trim()) {
						uni.showToast({
							icon: 'none',
							title: '请输入姓名'
						})
						return
					}
					if (!that.buy_phone.trim()) {
						uni.showToast({
							icon: 'none',
							title: '请输入电话'
						})
						return
					}
					if (!that.$reg.phone.test(that.buy_phone)) {
						uni.showToast({
							icon: 'none',
							title: '电话号码有误'
						})
						return
					}
					that.sumbmitName = that.buy_name;
					that.sumbmitPhone = that.buy_phone;
				}
				if (that.delivery == 1) { // 快递
					if (!that.addDetail.Aname) {
						uni.showToast({
							icon: 'none',
							title: '请选择收货地址'
						})
						return
					}
					that.sumbmitName = that.addDetail.Aname;
					that.sumbmitPhone = that.addDetail.Amobile;
				}
				if (that.buy_config.state == 1) { // 需要身份证
					if (that.ID_number == '') {
						uni.showToast({
							icon: 'none',
							title: '请输入身份证'
						})
						return
					}
					if (!that.$reg.idCard.test(that.ID_number)) {
						uni.showToast({
							icon: 'none',
							title: '身份证格式错误'
						})
						return
					}
					if (that.buy_config.max != 0 && that.buy_config.min != 0) {
						var strBirthday = that.ID_number.substr(6, 4) + '-' + that.ID_number.substr(10, 2) + '-' + that
							.ID_number.substr(12, 2)
						let hisAge = that.getAge(strBirthday)
						if (hisAge < parseFloat(that.buy_config.min) || hisAge > parseFloat(that.buy_config.max)) {
							uni.showToast({
								icon: "none",
								title: "只有" + that.buy_config.min + '岁到' + that.buy_config.max + '岁才能购买'
							})
							return
						}
					}

				}

				that.showModal = true;
			},
			paySure() {
				let that = this;

				let shareid = uni.getStorageSync("share_v_id");
				if (that.flagPay) {
					that.flagPay = false;
					/**
					 * 提交订单
					 * **/
					var params = {
							delivery: that.delivery, // 配送方式 1快递 2自提 5仓库
							receivingAddress: that.addDetail.Aregion + that.addDetail.Aaddress,
							uname: that.sumbmitName,
							utel: that.sumbmitPhone,
							express: that.pageData.express,
							totalMoney: that.paymentMoney, // 实付款
							remarks: that.ID_number ? that.remark + ',身份证号:' + that.ID_number : that.remark, // 备注信息
							couponID: that.couponID,
							useIntegral: that.useIntegral,
							aes_coupon: that.integralData.aes_coupon ? that.integralData.aes_coupon : '',
							share_v_id: shareid,
							group_id: that.group_id,
							shop_id: that.pageData.data[0].shop_id
						},
						apiUrl;

					if (that.goods_id) { // 普通下单
						apiUrl = '/zzj_singleSaleApi/generateOrder'
						params.goods_id = that.goods_id
						params.num = that.goods_num
						params.single = 1 // 普通商品下单
						params.specs_bind_id = that.specs.specs_bind_id ? that.specs.specs_bind_id : ''
						params.specs_bind_text = that.specs.specs_bind_text ? that.specs.specs_bind_text : ''
					}
					if (that.record_id) { // 砍价下单
						apiUrl = '/BargainApi/generateOrder'
						params.record_id = that.record_id
					}
					if (that.open_group == 1 || that.group_id) {
						params.single = 0 // 开团购买
					}
					if (that.car_id) { // 购物车下单
						apiUrl = '/zzj_singleSaleApi/storePayCart'
						params.couponsId = that.couponID
						params.car_id = that.car_id
					}
					this.$showLoading('支付中···')

					that.$http.post({
						url: apiUrl,
						data: params
					}).then(res => {
						this.$hideLoading()
						if (res.code == 100) {
							if (res.payID) {
								// #ifdef H5
								window.location.href =
									'https://sra.weikebaba.com/index.php/accountPay/weChatCashierPage?orderStr=' +
									res.payID
								// #endif
								// #ifndef H5
								uni.navigateTo({
									url: '/moneyPage/capital/checkstand?payid=' + res.payID + '&path=1'
								})
								// #endif

								return
							}
						}
						uni.showToast({
							icon: 'none',
							title: res.msg,
						})
						that.flagPay = true;

					})
				}
			},
			id_number_update(i) {
				let that = this;
				uni.hideKeyboard()
				that.showKeyBoard = true
				that.keyBoardNum = i
			},
			delNum() {
				let that = this;
				if (that.keyBoardNum == 1) {
					that.ID_number = that.ID_number.substring(0, that.ID_number.length - 1)
				}
				if (that.keyBoardNum == 2) {
					that.ID_number2 = that.ID_number2.substring(0, that.ID_number2.length - 1)
				}
			},
			checkNum(i) {
				let that = this;
				if (that.keyBoardNum == 1) {
					if (that.ID_number.length == 19) {
						uni.showToast({
							title: '身份证号码最多19位哦',
							icon: 'none'
						})
						return
					}
					that.ID_number = that.ID_number + i
				}
				if (that.keyBoardNum == 2) {
					if (that.ID_number.length == 19) {
						uni.showToast({
							title: '身份证号码最多19位哦',
							icon: 'none'
						})
						return
					}
					that.ID_number2 = that.ID_number2 + i
				}
			},
			// 根据日期计算年龄
			getAge(strBirthday) {
				//strBirthday传入格式 2020-04-15
				var returnAge;
				var strBirthdayArr = strBirthday.split('-');
				var birthYear = strBirthdayArr[0];
				var birthMonth = strBirthdayArr[1];
				var birthDay = strBirthdayArr[2];
				//获取当前日期
				var d = new Date();
				var nowYear = d.getFullYear();
				var nowMonth = d.getMonth() + 1;
				var nowDay = d.getDate();
				if (nowYear == birthYear) {
					returnAge = 0; //同年 则为0岁
				} else {
					var ageDiff = nowYear - birthYear; //年之差
					if (ageDiff > 0) {
						if (nowMonth == birthMonth) {
							var dayDiff = nowDay - birthDay; //日之差
							if (dayDiff < 0) {
								returnAge = ageDiff - 1;
							} else {
								returnAge = ageDiff;
							}
						} else {
							var monthDiff = nowMonth - birthMonth; //月之差
							if (monthDiff < 0) {
								returnAge = ageDiff - 1;
							} else {
								returnAge = ageDiff;
							}
						}
					} else {
						returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
					}
				}
				return returnAge; //返回周岁年龄
			},
			getPageData: function() { // 获取页面数据 （合并版）
				let that = this;
				let url = '/zzj_singleSaleApi/getPurchase'
				if (that.record_id) url = '/BargainApi/getPurchase'
				that.$http.get({
					url,
					data: {
						goods_id: that.goods_id ? that.goods_id : '',
						num: that.goods_num ? that.goods_num : '',
						specs_bind_id: that.specs.specs_bind_id ? that.specs.specs_bind_id : '',
						delivery: that.delivery,
						Aregion: that.Aregion,
						car_id: that.car_id ? that.car_id : '', // 购物车下单则传
						group_id: that.group_id ? that.group_id : '', // 参团则传
						open_group: that.open_group, // 是否为开团 1为开团
						record_id: that.record_id, // 砍价记录id
						shop_id: uni.getStorageSync('shop_id') ? uni.getStorageSync('shop_id') : '',
					}
				}).then(res => {
					if (res.code == 100 && res.data) {
						that.pageData = res;
						if (!that.paymentMoney)
							that.paymentMoney = res.all_payment

						if (that.delivery == 0) {
							if (that.pageData.deliverys.indexOf(",") == -1 && !that.pageData.deliverys) {
								that.delivery = that.pageData.deliverys;
							}
							const deliverysArr = that.pageData.deliverys.split(',');
							if (deliverysArr.length) that.delivery = deliverysArr[0];
						}


						// 开团/参团 无优惠
						if (that.open_group != 1 && !that.group_id) {
							that._getPreferential()
							that.getCoupon()
						}
						if (that.goods_id) { // 直接购买才有身份验证
							that.buy_config = JSON.parse(res.data[0].list[0].buy_config).id_number
						}
					}
				})
			},

			_getPreferential: function() { // 使用积分/优惠券
				let that = this;
				let apiUrl, params = {
					vId: that.vid,
					couponsId: that.couponID,
					express: that.pageData.express,
					useIntegral: that.useIntegral,
				};
				if (that.car_id) { // 购物车购买
					apiUrl = '/SRA_simMallApi/getPreferential2'
					params.carIds = that.car_id
					params.operationId = ''
				} else { // 单独购买
					apiUrl = '/SRA_simMallApi/getPreferential3'
					params.specs_bind_id = that.specs.specs_bind_id ? that.specs.specs_bind_id : ''
					params.goods_id = that.goods_id
					params.num = that.goods_num
					params.single = that.goods_id && that.open_group != 1 ? 1 : 0 // 正常购买
				}
				that.$http.get({
					url: apiUrl,
					data: params
				}).then(res => {
					if (res.code == 100 && res.data) {
						that.integralData = res.data
						console.log(that.integralData.payMoney)
						that.paymentMoney = that.integralData.payMoney
					}
				})
			},
			getCoupon: function() { // 获取优惠券列表
				let that = this;
				that.$http.get({
					url: '/SRA_simMallApi/getCoupons2',
					data: {
						vId: that.vid,
						operation_id: 0,
						carIds: that.car_id,
						goods_id: that.goods_id,
						num: that.goods_num,
					}
				}).then(res => {
					if (res.code == 100 && res.data) {
						that.couponsData = res.data
					}
				})
			},
			preferential: function(i) {
				let that = this;
				if (i == 0) { // 积分切换
					that.useIntegral = that.useIntegral == 1 ? 0 : 1
					that._getPreferential()
				} else { // 优惠券切换
					that.selectCouponIsShow = true
				}
			},
			_couponClick: function(couponId) {
				let that = this;
				that.couponID = couponId
				that._getPreferential()
				that.selectCouponIsShow = false
			}
		},

		computed: {
			...mapState(['System', 'navHeight', 'nameDefinition', 'share', 'vid', 'startUp'])
		},
		onPageScroll(e) {
			if (e.scrollTop > 200) {
				this.toTop = true;
			} else {
				this.toTop = false;
			}
		},
		onShareAppMessage(res) {
			let share = this.share;
			return {
				title: share.title,
				desc: share.desc,
				path: `/pages/index/index?share_v_id=${this.vid}&pageType=999`,
				imageUrl: `${share.imageUrl}`
			}
		},
	}
</script>

<style scoped lang="scss">
	.agoods_t {
		height: auto;
	}

	.selectStore {
		position: absolute;
		right: 30rpx;
		top: 50%;
		transform: translate(0, -50%);
	}

	.maskBg {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		background: #FFFFFF;
	}

	.footer_info {
		padding: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.ftr_info_oper_item2 {
			height: 98rpx;
		}
	}

	.addr_pop_ftr {
		width: 100%;
		padding: 30upx 0;
		background: #ffffff;
		position: absolute;
		bottom: 0;
		left: 0;
		z-index: 1;
		padding-bottom: calc(30rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
	}

	.page {
		background-color: #F8F8F8;
		padding-bottom: calc(100rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(100rpx + env(safe-area-inset-bottom));

		.store_addr {
			.store_addr_form {
				.input_box {
					padding-top: 20rpx;
					display: flex;
					align-items: center;

					.isKey {
						font-size: 28rpx;
					}

					input {
						flex: 1;
						font-size: 26rpx;
						color: #333333;
					}
				}
			}
		}

		.receipt_addr {
			margin: 30upx 0;
		}

		.r_addr_info_t {
			flex-wrap: wrap;

			text {
				font-size: 32rpx;
				font-weight: bold;
			}
		}

		.order_goods {
			margin-bottom: 30upx;
		}

		.addr_list {
			overflow-x: hidden;
			background: #FFFFFF;
			-webkit-overflow-scrolling: touch;

			.addr_item {
				height: 157upx;
				border-bottom: 1px solid #dddddd;
				padding: 0 30upx;
				position: relative;

				.addr_info_c {
					overflow: hidden;
					text-overflow: ellipsis;
					color: #666666;
				}

				.addr_info_h {
					overflow: hidden;
					text-overflow: ellipsis;
					margin-bottom: 15upx;
					font-size: 36upx;
					font-family: arial;
				}
			}
		}
	}

	.specs-show {
		// height: 62upx;
		display: flex;
		align-items: center;
		overflow: hidden;
	}

	.specs-show text {
		font-size: 22rpx;
		color: #999;
		background-color: #EEEEEE;
		border-radius: 4upx;
		padding: 4upx 8upx;
		// white-space: nowrap;
		// text-overflow: ellipsis;
	}


	.option_label .selects {
		transform: scale(0.7);
	}

	.option_label:nth-child(1) {
		margin-right: 20upx;
	}

	.agoods_thumb_img {
		width: 100%;
		height: 100%;
	}

	.editor_img {
		width: 36upx;
		height: 44upx;
	}

	.shop {
		margin-bottom: 20rpx;

		.shop-logo {
			width: 40rpx;
			height: 40rpx;
			border-radius: 6rpx;
			margin-right: 12rpx;
		}

		.name {
			font-size: 32rpx;
		}
	}

	.agoods {
		margin-top: 24rpx;
	}

	.agoods_info {
		flex-direction: column;
		justify-content: space-between;
	}

	.integralText {
		color: #ff4b4e;
	}

	.idCardBox {
		background-color: #FFFFFF;
		margin-top: 2rpx;
		line-height: 90rpx;
		padding: 0 30rpx;

		view {
			font-size: 28rpx;
		}

		.input {
			font-size: 28rpx;
			text-align: right;
			width: 100%;
			padding: 0 10rpx;
		}

		.pla {
			text-align: right;
			color: #999999;
		}
	}

	// 键盘样式
	.keyboard-box {
		position: fixed;
		z-index: 99999;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;

		.keyboard {
			height: 600rpx;
			width: 100%;
			background-color: #F4F4F4;
			position: absolute;
			bottom: 0;
			left: 0;
		}

		.keyboard-close {
			line-height: 80rpx;
			text-align: center;
			border-bottom: 2rpx solid rgba(255, 255, 255, .8);

			.icon-xiangxia {
				color: #666666;
				font-size: 36rpx;
			}
		}

		.key-box {
			width: 100%;
			height: 520rpx;
			flex-wrap: wrap;
			text-align: center;

			.key {
				width: 33.33%;
				height: 25%;
				border-right: 2rpx solid rgba(255, 255, 255, .8);
				border-bottom: 2rpx solid rgba(255, 255, 255, .8);

				&:nth-of-type(3n) {
					border-right: none;
				}

				&:nth-of-type(10),
				&:nth-of-type(11),
				&:nth-of-type(12) {
					border-bottom: none;
				}

				.key-txt {
					font-size: 40rpx;
					font-weight: bold;

					.icon-shanchu1 {
						font-weight: normal;
						color: #A8A2A1;
						font-size: 54rpx;
					}
				}
			}
		}
	}

	.cttxt {
		font-size: 32rpx;
		font-weight: bold;
	}
</style>